package com.ushine.design.design.c_behavioral_pattern.h_state.b_example;

public class Account {
    private AccountState state; //状态
    private String owner; //开户名
    private double balance = 0;//余额

    public void setState(AccountState state) {
        this.state = state;
    }

    public double getBalance() {
        return balance;
    }

    public void setBalance(double balance) {
        this.balance = balance;
    }

    public Account(String owner, double init) {
        this.state = new NormalState(this);
        this.owner = owner;
        this.balance = init;
        System.out.println(this.owner + "开户，初始化余额为" + init);
        System.out.println("----------------------------------------------");
    }

    public void deposit(double amount) {
        System.out.println(this.owner + "存款" + amount);
        state.deposit(amount);
        System.out.println("现在余额为：" + this.balance);
        System.out.println("现在账户状态为：" + this.state.getClass().getName());
        System.out.println("----------------------------------------------");
    }

    public void withdraw(double amount) {
        System.out.println(this.owner + "取款" + amount);
        state.withdraw(amount);
        System.out.println("现在余额为：" + this.balance);
        System.out.println("现在账户状态为：" + this.state.getClass().getName());
        System.out.println("----------------------------------------------");
    }

    public void computeInterest() {
        state.computeInterest();
    }

}
